package com.shop2cn.iapi.agentproducts.testcase;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.shop2cn.iapi.agentproducts.parameter.AddAgentProductBean;
import com.shop2cn.iapi.agentproducts.parameter.ImportAgentProductBean;
import com.shop2cn.iapi.agentproducts.parameter.RemoveAgentCallbackBean;
import com.shop2cn.iapi.agentproducts.service.RemoveAgentCallbackCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymttest.business.service.AddAgentProductCallService;
import com.ymttest.database.sqlwapper.YmtProductsIWapper;
import com.ymttest.utils.AgentUsers;

/**
*移除代理
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_RemoveAgentCallback{
	private static RemoveAgentCallbackBean removeagentcallbackBean;
	private static RemoveAgentCallbackCall removeagentcallbackCall;
	private static YmtProductsIWapper ymtProductsIWapper = new YmtProductsIWapper();

	//渠道商
	private static int sellerId = AgentUsers.rootUserId;
	private static String sellerName = "NickautoTest";
	//渠道商->代理商1
	private static int agentUserId1 = AgentUsers.agentUserId1;
	private static String agentUserName1 = "NickautoTest";
	//渠道商->代理商2
	private static int agentUserId2 = AgentUsers.agentUserId2;
	private static String agentUserName2 = "NickautoTest";

	//vip渠道
	private static int vipRootUserId = AgentUsers.vipRootUserId;
	private static String vipRootUserName = "NickautoTest";
	//vip渠道->代理
	private static int vipAgentUserId1 = AgentUsers.vipAgentUserId1;
	private static String vipAgentUserName1 = "dgsq408897016";
	//vip渠道->代理->代理
	private static int vipAgentUserId2 = AgentUsers.vipAgentUserId2;
	private static String vipAgentUserName2 = "NickautoTest";
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("移除代理");
	}

	@Before
	public void caseUp() {
		removeagentcallbackBean=new RemoveAgentCallbackBean();
		removeagentcallbackCall=new RemoveAgentCallbackCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(removeagentcallbackCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_RemoveAgentCallback_01() {
		Logger.start(true,"普通渠道商移除代理");
		try {
			//vip渠道
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(sellerId,sellerName,true);
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			//vip代理1
			ImportAgentProductBean importAgentProductBean = AddAgentProductCallService.initImportAgentProduct(agentUserId1,agentUserName1,productId,sellerId,false);
			String agentProductId = AddAgentProductCallService.ImportAgentProduct(importAgentProductBean);

			removeagentcallbackBean.setUserId(sellerId);
			removeagentcallbackBean.setRemovedUserId(agentUserId1);
			removeagentcallbackCall.setData(removeagentcallbackBean);
			removeagentcallbackCall.callService();
			Thread.sleep(5000);
			Logger.verifyEquals(-1,ymtProductsIWapper.selectAgentProductByProductId(agentProductId).getAction(),"验证下级代理商商品action-2");
			Logger.verifyEquals(-1,ymtProductsIWapper.selectProductByProductId(agentProductId).get(0).getiAction(),"验证下级代理商商品action-2");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_RemoveAgentCallback_02() {
		Logger.start(true,"vip渠道->vip1->vip2,vip渠道移除代理");
		try {
			//vip渠道
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(vipRootUserId,vipRootUserName,true);
			addAgentProductBean.getCatalogList().get(0).getAgentPriceList().get(1).setAgentPrice(300);
			addAgentProductBean.getCatalogList().get(1).getAgentPriceList().get(1).setAgentPrice(300);
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			//vip代理1
			ImportAgentProductBean importAgentProductBean = AddAgentProductCallService.initImportAgentProduct(vipAgentUserId1,vipAgentUserName1,productId,vipRootUserId,true);
			String agentProductId = AddAgentProductCallService.ImportAgentProduct(importAgentProductBean);
			//vip代理2
			ImportAgentProductBean importAgentProductBean1 = AddAgentProductCallService.initImportAgentProduct(vipAgentUserId2,vipAgentUserName2,agentProductId,vipAgentUserId1,false);
			String agentProductId1 = AddAgentProductCallService.ImportAgentProduct(importAgentProductBean1);

			removeagentcallbackBean.setUserId(vipRootUserId);
			removeagentcallbackBean.setRemovedUserId(vipAgentUserId1);
			removeagentcallbackCall.setData(removeagentcallbackBean);
			removeagentcallbackCall.callService();

			Thread.sleep(5000);
			Logger.verifyEquals(-1,ymtProductsIWapper.selectAgentProductByProductId(agentProductId).getAction(),"验证下级代理商商品action-2");
			Logger.verifyEquals(-1,ymtProductsIWapper.selectAgentProductByProductId(agentProductId1).getAction(),"验证下级代理商商品action-2");

			Logger.verifyEquals(-1,ymtProductsIWapper.selectProductByProductId(agentProductId).get(0).getiAction(),"验证商品被删除");
			Logger.verifyEquals(-1,ymtProductsIWapper.selectProductByProductId(agentProductId1).get(0).getiAction(),"验证商品被删除");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}


	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_RemoveAgentCallback_03() {
		Logger.start(true,"vip渠道->vip1->vip2,vip1移除代理");
		try {
			//vip渠道
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(vipRootUserId,vipRootUserName,true);
			addAgentProductBean.getCatalogList().get(0).getAgentPriceList().get(1).setAgentPrice(300);
			addAgentProductBean.getCatalogList().get(1).getAgentPriceList().get(1).setAgentPrice(300);
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			//vip代理1
			ImportAgentProductBean importAgentProductBean = AddAgentProductCallService.initImportAgentProduct(vipAgentUserId1,vipAgentUserName1,productId,vipRootUserId,true);
			String agentProductId = AddAgentProductCallService.ImportAgentProduct(importAgentProductBean);
			//vip代理2
			ImportAgentProductBean importAgentProductBean1 = AddAgentProductCallService.initImportAgentProduct(vipAgentUserId2,vipAgentUserName2,agentProductId,vipAgentUserId1,false);
			String agentProductId1 = AddAgentProductCallService.ImportAgentProduct(importAgentProductBean1);

			removeagentcallbackBean.setUserId(vipAgentUserId1);
			removeagentcallbackBean.setRemovedUserId(vipAgentUserId2);
			removeagentcallbackCall.setData(removeagentcallbackBean);
			removeagentcallbackCall.callService();

			Thread.sleep(5000);
			Logger.verifyEquals(-1,ymtProductsIWapper.selectAgentProductByProductId(agentProductId1).getAction(),"验证下级代理商商品action-2");

			Logger.verifyEquals(-1,ymtProductsIWapper.selectProductByProductId(agentProductId1).get(0).getiAction(),"验证商品被删除");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_RemoveAgentCallback_04() {
		Logger.start(true,"渠道商->代理1，渠道商->代理2,移除代理1类型，验证代理1和代理2商品状态");
		try {
			//vip渠道
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(vipRootUserId,vipRootUserName,true);
			addAgentProductBean.getCatalogList().get(0).getAgentPriceList().get(1).setAgentPrice(300);
			addAgentProductBean.getCatalogList().get(1).getAgentPriceList().get(1).setAgentPrice(300);
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			//vip代理1
			ImportAgentProductBean importAgentProductBean = AddAgentProductCallService.initImportAgentProduct(vipAgentUserId1,vipAgentUserName1,productId,vipRootUserId,true);
			String agentProductId = AddAgentProductCallService.ImportAgentProduct(importAgentProductBean);
			//vip代理2
			ImportAgentProductBean importAgentProductBean1 = AddAgentProductCallService.initImportAgentProduct(vipAgentUserId2,vipAgentUserName2,agentProductId,vipAgentUserId1,false);
			String agentProductId1 = AddAgentProductCallService.ImportAgentProduct(importAgentProductBean1);

			removeagentcallbackBean.setUserId(vipAgentUserId1);
			removeagentcallbackBean.setRemovedUserId(vipAgentUserId2);
			removeagentcallbackCall.setData(removeagentcallbackBean);
			removeagentcallbackCall.callService();

			Thread.sleep(5000);
			Logger.verifyEquals(-1,ymtProductsIWapper.selectAgentProductByProductId(agentProductId1).getAction(),"验证下级代理商商品action-2");

			Logger.verifyEquals(-1,ymtProductsIWapper.selectProductByProductId(agentProductId1).get(0).getiAction(),"验证商品被删除");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

}